package com.wnzt.baszh.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;







import com.wnzt.baszh.entity.Tsysuser;
import com.wnzt.baszh.service.IPrintService;
import com.wnzt.baszh.util.common.GlobalStatic;
import com.wnzt.baszh.util.common.PageHelper;
/**
 * 打印
 * @author dqw
 * @date 2017-4-11
 */
@Controller
@RequestMapping("/Print")
public class PrintController {
	
	
	@Autowired
	private IPrintService printService;
	
	/**
	 * 跳转打印查询页面
	 * @return
	 */
	@RequestMapping("/PrintQuery")
    public String PrintQuery() {
        return "Print/PrintQuery";
    }
	
	/**
	 * 跳转打印登记页面
	 * @return
	 */
	@RequestMapping("/PrintScanning")
    public String PrintScanning() {	
        return "Print/PrintScanning";
    }
	
	/**
	 * 跳转打印页面
	 * @return
	 */
	@RequestMapping("/PrintPage")
    public String PrintPage(Model model) {	
		List list = printService.getBAXM();
		model.addAttribute("PrintModel", list);
        return "Print/PrintPage";
    }
	
/**********************************************************************************************************/	
	
	/**
	 * 获取所有科室
	 * @return
	 */
	@RequestMapping("/getDept")
	@ResponseBody
	public Object getDept(HttpServletRequest request ){
		List list = printService.getDept();
    	return list;
	}
	
	/**
	 * 获取打印查询页面数据
	 * @param request
	 * @return
	 */
	@RequestMapping("/printDataQuery")
	@ResponseBody
	public Object printDataQuery(HttpServletRequest request ){
		String date1 = request.getParameter("date1");
		String date2 = request.getParameter("date2");
		String fcydept = request.getParameter("fcydept");
		String fprn = request.getParameter("fprn");
		String ftimes = request.getParameter("ftimes");
		String fbarcode = request.getParameter("fbarcode");
		String fname = request.getParameter("fname");
		String fsex = request.getParameter("fsex");
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("date1", date1);
		map.put("date2", date2);
		map.put("fcydept", fcydept);
		map.put("fprn", fprn);
		map.put("ftimes", ftimes);
		map.put("fbarcode", fbarcode);
		map.put("fname", fname);
		map.put("fsex", fsex);
		map.put("page", page);
		map.put("rows", rows);
		PageHelper pageHelper = printService.printDataQuery(map);
		return pageHelper;
	}
	
	/**
	 * 跳转打印登记页面，并将打印内容传入前台
	 */
	@RequestMapping("/PrintRegister")
	public Object PrintRegister(HttpServletRequest request ,Model model){
		List list = printService.getBAXM();
		model.addAttribute("contentModel", list);
		return "Print/PrintRegister";
	}
	
	/**
	 * 获取与患者关系字段
	 * @param request
	 * @return
	 */
	@RequestMapping("/queryRelation")
	@ResponseBody
	public Object queryRelation(HttpServletRequest request ){
		List list = printService.queryRelation();
		return list;
	}
	
	/**
	 * 获取打印类型
	 * @param request
	 * @return
	 */
	@RequestMapping("/getPrintType")
	@ResponseBody
	public Object getPrintType(HttpServletRequest request ){
		List list = printService.getPrintType();
		return list;
	}
	
	/**
	 * 打印登记
	 * @param request
	 * @return
	 */
	@RequestMapping("/RegisterPrint")
	@ResponseBody
	public Object RegisterPrint(HttpServletRequest request ){
		//获取当前用户
		Tsysuser user = (Tsysuser) request.getSession().getAttribute(GlobalStatic.USER_SESSION_OBJECT);
		String name = user.getFname();//用户名
		String fcode = user.getFcode();	//当前用户编号
		String fcydate = request.getParameter("fcydate");
		String purpose = request.getParameter("purpose");
		String purposeText = request.getParameter("purposeText");
		String relationText = request.getParameter("relationText");
		String relation = request.getParameter("relation");
		String IDCard = request.getParameter("IDCard");
		String printMan = request.getParameter("printMan");
		String address = request.getParameter("address");
		String fzyid = request.getParameter("fzyid");
		String fname = request.getParameter("fname");
		String content = request.getParameter("content");
		String DATE = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("fcydate", fcydate);
		map.put("purpose", purpose);
		map.put("purposeText", purposeText);
		map.put("relationText", relationText);
		map.put("relation", relation);
		map.put("IDCard",IDCard );
		map.put("printMan", printMan);
		map.put("address", address);
		map.put("fzyid", fzyid);
		map.put("fname", fname);
		map.put("content", content);
		map.put("curName", name);
		map.put("fcode", fcode);
		map.put("date", DATE);
		boolean flag = printService.printRegister(map);
		return flag;
	}
	
	/**
	 * 保存收费信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/savePrintCharge")
	@ResponseBody
	public Object savePrintCharge(HttpServletRequest request ){
		//获取当前用户
		Tsysuser user = (Tsysuser) request.getSession().getAttribute(GlobalStatic.USER_SESSION_OBJECT);
		String name = user.getFname();//用户名
		String fzyid = request.getParameter("fzyid");
		String page = request.getParameter("page");
		String copies = request.getParameter("copies");
		String total = request.getParameter("total");
		String DATE = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("name", name);
		map.put("fzyid", fzyid);
		map.put("page", page);
		map.put("copies", copies);
		map.put("total", total);
		map.put("date", DATE);
		boolean result = printService.savePrintCharge(map);
		return result;
	}
	/**
	 * 跳转到快速打印页面
	 */
	@RequestMapping("/FastPrint")
	public Object FastPrint(HttpServletRequest request ,Model model){
		List list = printService.getBAXM();
		model.addAttribute("contentModel", list);
		return "Print/FastPrint";
	}
	/**
	 * 获取主治医生
	 * @param request
	 * @return
	 */
	@RequestMapping("/getZzDoc")
	@ResponseBody
	public Object getZzDoc(HttpServletRequest request){
		List<Map<String, Object>> list = printService.getZzDoc();
		return list;
	}
	/**
	 * 获取出院病室
	 * @param request
	 * @return
	 */
	@RequestMapping("/getFcybs")
    @ResponseBody
    public Object getFcybs(HttpServletRequest request){
		String ksbh = request.getParameter("ksbh"); //科室编号
		String fcode = request.getParameter("fcode"); //当前用户编码
		List<Map<String, Object>> list = printService.getFcybs(ksbh,fcode);
		return list;
	}
	
	/**
	 * 获取打印查询页面数据
	 * @param request
	 * @return
	 */
	@RequestMapping("/fastPrintQuery")
	@ResponseBody
	public Object fastPrintQuery(HttpServletRequest request ){
		String date1 = request.getParameter("date1");
		String date2 = request.getParameter("date2");
		String fcydept = request.getParameter("fcydept");
		String fcybq = request.getParameter("fcybq");
		String fprn = request.getParameter("fprn");
		String fname = request.getParameter("fname");
		String fzydoc = request.getParameter("fzydoc");
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("date1", date1);
		map.put("date2", date2);
		map.put("fcydept", fcydept);
		map.put("fcybq", fcybq);
		map.put("fprn", fprn);
		map.put("fname", fname);
		map.put("fzydoc", fzydoc);
		map.put("page", page);
		map.put("rows", rows);
		PageHelper pageHelper = printService.fastPrintQuery(map);
		return pageHelper;
	}
	
	/**
	 * 跳转复印登记页面，并将打印内容传入前台
	 */
	@RequestMapping("/CopyRegister")
	public Object CopyRegister(HttpServletRequest request ,Model model){
		List list = printService.getBAXM();
		model.addAttribute("contentModel", list);
		return "Print/CopyRegister";
	}

	/**
	 * 跳转预约批量打印页面
	 * @return
	 */
	@RequestMapping("/BatchPrint")
    public String BatchPrint() {
        return "Print/BatchPrint";
    }
	
	/**
	 * 预约批量打印查询页面数据
	 * @param request
	 * @return
	 */
	@RequestMapping("/batchPrintQuery")
	@ResponseBody
	public Object batchPrintQuery(HttpServletRequest request ){
		String date1 = request.getParameter("date1");
		String date2 = request.getParameter("date2");
		String fcydept = request.getParameter("fcydept");
		String fcybq = request.getParameter("fcybq");
		String fprn = request.getParameter("fprn");
		String fname = request.getParameter("fname");
		String fzydoc = request.getParameter("fzydoc");
		String page = request.getParameter("page");
		String rows = request.getParameter("rows");
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("date1", date1);
		map.put("date2", date2);
		map.put("fcydept", fcydept);
		map.put("fcybq", fcybq);
		map.put("fprn", fprn);
		map.put("fname", fname);
		map.put("fzydoc", fzydoc);
		map.put("page", page);
		map.put("rows", rows);
		PageHelper pageHelper = printService.batchPrintQuery(map);
		return pageHelper;
	}
	
	/**
	 * 跳转复印/打印记录页面
	 * @return
	 */
	@RequestMapping("/CopyPrintRecord")
    public String CopyPrintRecord() {
        return "Print/CopyPrintRecord";
    }
	
    /**
     * 复印/打印记录返回
     */
    @RequestMapping("copyPrintRecordSearch")
    @ResponseBody
    public Object copyPrintRecordSearch(HttpServletRequest request){
        

        String FCYDATE = request.getParameter("FCYDATE");                //日期类型(复印申请日期、出院日期)
        String FQSDATE = request.getParameter("FQSDATE");                //起始日期()
        String FJSDATE = request.getParameter("FJSDATE");                //结束日期()
        String FCYKS = request.getParameter("FCYKS");                 	 //出院科室
        
        String FCZY = request.getParameter("FCZY");                  	 //操作员
        String FPRNTEXT = request.getParameter("FPRNTEXT");        	     //病案号值,同时将中文逗号转英文逗号
        String FNAME = request.getParameter("FNAME");                    //姓名
         
        String FSTATE = request.getParameter("FSTATE");   
        String page = request.getParameter("page");
		String rows = request.getParameter("rows");
        Map<String, Object> map = new HashMap<String,Object>();
        if (!"".equals(FPRNTEXT)) {
            FPRNTEXT = FPRNTEXT.replaceAll("，", ",");
        }
        if (!"".equals(FNAME)) {
        	FNAME = FNAME.replaceAll("，", ",");
        }
 
        map.put("FCYDATE", FCYDATE);
        map.put("FQSDATE", FQSDATE);
        map.put("FJSDATE", FJSDATE);
        map.put("FCYKS", FCYKS);  
        map.put("FCZY", FCZY);
        map.put("FPRNTEXT", FPRNTEXT);
        map.put("FNAME", FNAME);     
        map.put("FSTATE", FSTATE);
        map.put("page", page);
		map.put("rows", rows);
        PageHelper pageHelper = printService.copyPrintRecordSearch(map);
		return pageHelper;
    }
    
    /**
	 * 跳转病案打印页面
	 * @return
	 */
	@RequestMapping("/MedicalRecordPrintSet")
    public String MedicalRecordPrintSet() {
        return "Print/MedicalRecordPrintSet";
    }
	
	 /**
     * 加载所有打印复印目的
     * return 
     */
    @RequestMapping("printPurposeSet")
    @ResponseBody
    public Object printPurposeSet(HttpServletRequest request){
        return printService.printPurposeSet();
    }
    
    /**
     * 根据打印复印的id加载打印分类及顺序
     * return 
     */
    @RequestMapping("showPrintSetOrder")
    @ResponseBody
    public Object showPrintSetOrder(HttpServletRequest request){
        String fcode = request.getParameter("fcode");  //打印复印id
        return printService.showPrintSetOrder(fcode);
    }
    
    /**
	 * 添加打印目的
	 * return 
	 */
	@RequestMapping("addPrintPurpose")
	@ResponseBody
	public Object addPrintPurpose(HttpServletRequest request){
		String FCODE = request.getParameter("FCODE"); //打印编号
		String FNAME = request.getParameter("FNAME"); //打印目的或者名称
		String FZJC = request.getParameter("FZJC"); //打印助记词
        return printService.addPrintPurpose(FCODE,FNAME,FZJC);
	}
	
	/**
	 * 修改打印目的
	 * return 
	 */
	@RequestMapping("editPrintPurpose")
	@ResponseBody
	public Object editPrintPurpose(HttpServletRequest request){
		String FID = request.getParameter("FID"); //打印编号
		String FCODE = request.getParameter("FCODE"); //打印编号
		String FNAME = request.getParameter("FNAME"); //打印目的或者名称
		String FZJC = request.getParameter("FZJC"); //打印助记词
        return printService.editPrintPurpose(FID,FCODE,FNAME,FZJC);
	}
	
	/**
	 * 删除借阅目的
	 * return 
	 */
	@RequestMapping("deletePrintPurpose")
	@ResponseBody
	public Object deletePrintPurpose(HttpServletRequest request){
		String FID = request.getParameter("FID"); //权限编号或名称
		System.out.println(FID);
        return printService.deletePrintPurpose(FID);
	}
	
	/**
	 * 获取所有的打印目的
	 * return 
	 */
	@RequestMapping("checkAllPrintPurpose")
	@ResponseBody
	public Object checkAllBorrowPurpose(){
        return printService.checkAllPrintPurpose();
	}
	

}
